home *** CD-ROM | disk | FTP | other *** search
/ TOS Silver 2000 / TOS Silver 2000.iso / programm / MM2_DEV / S / DEMO / DHRYSTON.ADA / D_MAIN.M < prev    next >
Encoding:
Text File  |  1991-01-02  |  8.5 KB  |  284 lines

  1. MODULE D_Main;
  2.  
  3. (*$R-,S-,Z+ *)
  4.  
  5. FROM InOut     IMPORT Read, WriteString, WriteLn, ReadInt, WriteInt, Write;
  6. FROM InOut     IMPORT WriteReal;
  7. FROM Storage   IMPORT ALLOCATE;
  8. FROM TimeDate  IMPORT Clock;  (* system dependent !! *)
  9.  
  10. FROM D_Global  IMPORT OneToThirty, OneToFifty, Enumeration, String30,
  11.                       RecordPointer, Array1DimInteger, Array2DimInteger,
  12.                       RecordType;
  13. FROM D_Pack_1  IMPORT Proc1, Proc2, Proc3, Proc4, Proc5, NextPointerGlob,
  14.                       PointerGlob, Char2Glob, Array1Glob, Array2Glob, BoolGlob;
  15. FROM D_Pack_2  IMPORT Proc6, Proc7, Proc8, Func1, Func2, IntGlob, Char1Glob;
  16.  
  17. CONST (* for measurement *)
  18.  
  19.   MicrosecondsPerClock  = 5000;
  20.   ClocksPerSecond       = 200;
  21.         (* On the Atari ST we use the 200 Hz timer value        *)
  22.   TooSmallTime          = 1000;
  23.         (* Measurements should last at least 1000 samples       *)
  24.  
  25. VAR
  26.  
  27.   (* Ada version: Variables local in Proc_0 *)
  28.  
  29.   Int1Glob,
  30.   Int2Glob,
  31.   Int3Glob:       OneToFifty;
  32.   CharIndex:      CHAR;
  33.   EnumGlob:       Enumeration;
  34.   String1Glob,
  35.   String2Glob:    String30;
  36.  
  37.   (* Variables for measurement *)
  38.  
  39.   RunIndex,
  40.   NumberOfRuns:         INTEGER;
  41.   BeginClock,
  42.   EndClock,
  43.   SumClocks:            LONGINT;     (* system dependent !!! *)
  44.   Microseconds,
  45.   DhrystonesPerSecond:  REAL;
  46.   I:                    INTEGER;
  47.  
  48.   (* end of variables for measurement *)
  49.  
  50.   dummy : CHAR;
  51.   
  52. BEGIN (* main program, corresponds to procedures        *)
  53.       (* Main and Proc_0 in the Ada version             *)
  54.  
  55.   (* Initializations *)
  56.  
  57.   ALLOCATE (NextPointerGlob, SIZE(RecordType));
  58.  
  59.   ALLOCATE (PointerGlob, SIZE(RecordType));
  60.  
  61.   PointerGlob^.PointerComp := NextPointerGlob;
  62.   PointerGlob^.Discr       := Ident1;
  63.   PointerGlob^.EnumComp    := Ident3;
  64.   PointerGlob^.IntComp     := 40;
  65.   PointerGlob^.StringComp  := "DHRYSTONE PROGRAM, SOME STRING";
  66.  
  67.   String1Glob := "DHRYSTONE PROGRAM, 1'ST STRING";
  68.  
  69.   Array2Glob [8,7] := 10;
  70.  
  71.   WriteLn;
  72.   WriteString ('Dhrystone Benchmark, Version 2.1 (Language: Modula-2)');
  73.   WriteLn;
  74.   WriteLn;
  75.   WriteString ('Please give the number of runs through the benchmark: ');
  76.   ReadInt (NumberOfRuns);
  77.   WriteLn;
  78.   WriteString ('Execution starts, ');
  79.   WriteInt (NumberOfRuns,7);
  80.   WriteString (' runs through Dhrystone');
  81.   WriteLn;
  82.   WriteLn;
  83.  
  84.   Clock (BeginClock);
  85.  
  86.   (***************)
  87.   (* Start timer *)
  88.   (***************)
  89.  
  90.   FOR RunIndex := 1 TO NumberOfRuns DO
  91.  
  92.      Proc5;
  93.      Proc4;
  94.       (* Char1Glob = 'A', Char2Glob = 'B', BoolGlob = false *)
  95.      Int1Glob := 2;
  96.      Int2Glob := 3;
  97.      String2Glob := "DHRYSTONE PROGRAM, 2'ND STRING";
  98.      EnumGlob := Ident2;
  99.      BoolGlob := NOT Func2 (String1Glob, String2Glob);
  100.       (* BoolGlob = true *)
  101.      WHILE Int1Glob < Int2Glob DO  (* loop body executed once *)
  102.         Int3Glob := 5 * Int1Glob - Int2Glob;
  103.          (* Int3Glob = 7 *)
  104.         Proc7 (Int1Glob, Int2Glob, Int3Glob);
  105.          (* Int3Glob = 7 *)
  106.         Int1Glob := Int1Glob + 1;
  107.      END; (* while *)
  108.       (* Int1Glob = 3 *)
  109.      Proc8 (Array1Glob, Array2Glob, Int1Glob, Int3Glob);
  110.       (* IntGlob = 5 *)
  111.      Proc1 (PointerGlob);
  112.      FOR CharIndex := 'A' TO Char2Glob DO   (* loop body executed twice *)
  113.         IF EnumGlob = Func1 (CharIndex, 'C') THEN
  114.            (* not executed *)
  115.            Proc6 (Ident1, EnumGlob);
  116.            String2Glob := "DHRYSTONE PROGRAM, 3'RD STRING";
  117.            Int2Glob := RunIndex;
  118.            IntGlob := RunIndex;
  119.         END;
  120.      END;
  121.       (* Int1Glob = 3, Int2Glob = 3, Int3Glob = 7 *)
  122.      Int2Glob := Int2Glob * Int1Glob;
  123.      Int1Glob := Int2Glob DIV Int3Glob;
  124.      Int2Glob := 7 * (Int2Glob - Int3Glob) - Int1Glob;
  125.       (* Int1Glob = 1, Int2Glob = 13, Int3Glob = 7 *)
  126.      Proc2 (Int1Glob);
  127.       (* Int1Glob = 5 *)
  128.  
  129.   END; (* for RunIndex *)
  130.  
  131.   Clock (EndClock);
  132.  
  133.   (**************)
  134.   (* Stop timer *)
  135.   (**************)
  136.  
  137.   WriteString ('Execution ends');
  138.   WriteLn;
  139.   WriteLn;
  140.   
  141. (*
  142.   WriteString ('Final values of the variables used in the benchmark:');
  143.   WriteLn;
  144.   WriteLn;
  145.  
  146.   WriteString ('IntGlob:                      ');
  147.   WriteInt (IntGlob, 5);
  148.   WriteLn;
  149.   WriteString ('        should be:                5');
  150.   WriteLn;
  151.   WriteString ('BoolGlob:                      ');
  152.   IF BoolGlob = TRUE THEN
  153.      WriteString ('TRUE'); WriteLn;
  154.   ELSE
  155.      WriteString ('FALSE'); WriteLn;
  156.   END;
  157.   WriteString ('        should be:             TRUE');
  158.   WriteLn;
  159.   WriteString ('Char1Glob:                        ');
  160.   Write (Char1Glob);
  161.   WriteLn;
  162.   WriteString ('        should be:                A');
  163.   WriteLn;
  164.   WriteString ('Char2Glob:                        ');
  165.   Write (Char2Glob);
  166.   WriteLn;
  167.   WriteString ('        should be:                B');
  168.   WriteLn;
  169.   WriteString ('Array1Glob [8]:               ');
  170.   WriteInt (Array1Glob [8],5);
  171.   WriteLn;
  172.   WriteString ('        should be:                7');
  173.   WriteLn;
  174.   WriteString ('Array2Glob [8,7]:             ');
  175.   WriteInt (Array2Glob [8,7],5);
  176.   WriteLn;
  177.   WriteString ('        should be:                NumberOfRuns + 10');
  178.   WriteLn;
  179.   WriteString ('PointerGlob^.Discr:           ');
  180.   WriteInt (ORD(PointerGlob^.Discr),5);
  181.   WriteLn;
  182.   WriteString ('        should be:                0');
  183.   WriteLn;
  184.   WriteString ('PointerGlob^.EnumComp:        ');
  185.   WriteInt (ORD(PointerGlob^.EnumComp),5);
  186.   WriteLn;
  187.   WriteString ('        should be:                2');
  188.   WriteLn;
  189.   WriteString ('PointerGlob^.IntComp  :       ');
  190.   WriteInt (PointerGlob^.IntComp,5);
  191.   WriteLn;
  192.   WriteString ('        should be:               17');
  193.   WriteLn;
  194.   WriteString ('PointerGlob^.StringComp:     ');
  195.   FOR I := 1 TO 30 DO
  196.     Write (PointerGlob^.StringComp [I]);
  197.   END;
  198.   WriteLn;
  199.   WriteString ('        should be:           DHRYSTONE PROGRAM, SOME STRING');
  200.   WriteLn;
  201.   WriteString ('NextPointerGlob^.Discr:       ');
  202.   WriteInt (ORD(NextPointerGlob^.Discr),5);
  203.   WriteLn;
  204.   WriteString ('        should be:                0');
  205.   WriteLn;
  206.   WriteString ('NextPointerGlob^.EnumComp:    ');
  207.   WriteInt (ORD(NextPointerGlob^.EnumComp),5);
  208.   WriteLn;
  209.   WriteString ('        should be:                1');
  210.   WriteLn;
  211.   WriteString ('NextPointerGlob^.IntComp:     ');
  212.   WriteInt (NextPointerGlob^.IntComp,5);
  213.   WriteLn;
  214.   WriteString ('        should be:               18');
  215.   WriteLn;
  216.   WriteString ('NextPointerGlob^.StringComp: ');
  217.   FOR I := 1 TO 30 DO
  218.     Write (NextPointerGlob^.StringComp [I]);
  219.   END;
  220.   WriteLn;
  221.   WriteString ('        should be:           DHRYSTONE PROGRAM, SOME STRING');
  222.   WriteLn;
  223.   WriteString ('Int1Glob:                     ');
  224.   WriteInt (Int1Glob, 5);
  225.   WriteLn;
  226.   WriteString ('        should be:                5');
  227.   WriteLn;
  228.   WriteString ('Int2Glob:                     ');
  229.   WriteInt (Int2Glob, 5);
  230.   WriteLn;
  231.   WriteString ('        should be:               13');
  232.   WriteLn;
  233.   WriteString ('Int3Glob:                     ');
  234.   WriteInt (Int3Glob, 5);
  235.   WriteLn;
  236.   WriteString ('        should be:                7');
  237.   WriteLn;
  238.   WriteString ('EnumGlob:                     ');
  239.   WriteInt (ORD(EnumGlob),5);
  240.   WriteLn;
  241.   WriteString ('        should be:                1');
  242.   WriteLn;
  243.   WriteString ('String1Glob:                 ');
  244.   FOR I := 1 TO 30 DO
  245.     Write (String1Glob [I]);
  246.   END;
  247.   WriteLn;
  248.   WriteString ("        should be:           DHRYSTONE PROGRAM, 1'ST STRING");
  249.   WriteLn;
  250.   WriteString ('String2Glob:                 ');
  251.   FOR I := 1 TO 30 DO
  252.     Write (String2Glob [I]);
  253.   END;
  254.   WriteLn;
  255.   WriteString ("        should be:           DHRYSTONE PROGRAM, 2'ND STRING");
  256.   WriteLn;
  257.   WriteLn;
  258.   WriteLn;
  259. *)
  260.  
  261.   SumClocks := EndClock - BeginClock;
  262.  
  263.   IF SumClocks < TooSmallTime THEN
  264.      WriteString ('Measured time too small to obtain meaningful results');
  265.      WriteLn;
  266.      WriteString ('Please increase number of runs');
  267.      WriteLn;
  268.   ELSE
  269.      Microseconds := FLOAT(SumClocks) *
  270.                           (FLOAT(MicrosecondsPerClock) / FLOAT(NumberOfRuns));
  271.                                (* Brackets to prevent integer overflow *)
  272.      DhrystonesPerSecond := FLOAT (NumberOfRuns) *
  273.                               (FLOAT(ClocksPerSecond) / FLOAT(SumClocks));
  274.      WriteString ('Microseconds for one run through Dhrystone: ');
  275.      WriteReal   (Microseconds,8,8);
  276.      WriteLn;
  277.      WriteString ('Dhrystones per Second:                      ');
  278.      WriteReal   (DhrystonesPerSecond,8,8);
  279.      WriteLn;
  280.      WriteLn;
  281.    END;
  282.    
  283.   WriteLn; WriteString ('Taste...'); Read (dummy)
  284. END D_Main.